<template>
    <el-container class="home-container">
        <el-header>
            <div class="titel">
                <img src="../assets/images/Logos.png" alt="">
                <span>后台管理系统</span>
            </div>
            <el-button type="info" @click="logout">退出</el-button>
        </el-header>
        <el-container>
            <el-aside :width="isCollapse?'64px':'200px'">
                <div class="toggle-button" @click="toggleButton">|||</div>
               <el-menu 
               width="200px"
               background-color="#333744" 
               text-color="#fff" 
               :collapse="isCollapse" 
               :collapse-transition="false"
               :router="true"
               >
                    <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.username">
                        <template slot="title">
                            <i :class="iconObj[item.id]"></i>
                            <span>{{item.username}}</span>
                        </template>
                        <el-menu-item :index="subItem.path" v-for="subItem in item.children" :key="subItem.username">
                            <i class="el-icon-menu"></i>
                            <span>{{subItem.childrenName}}</span>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
export default {
    data(){
        return{
            menuList:[
                {username:"用户管理",id:1,children:[{childrenName:"用户列表",id:101,path:"/home/users"}]},
                {username:"商品管理",id:2,children:[{childrenName:"商品分类",id:102,path:"/home/classify"},{childrenName:"商品列表",id:111,path:"/home/goodslist"}]},
                {username:"权限管理",id:3,children:[{childrenName:"用户权限",id:103,path:"/home/root"}]},
                {username:"订单管理",id:4,children:[{childrenName:"订单列表",id:104,path:"/home/indent"}]},
                {username:"数据统计",id:5,children:[{childrenName:"数据列表",id:105,path:"/home/data"}]}
            ],
            iconObj:{
                '1':'el-icon-user-solid',
                '2':'el-icon-goods',
                '3':'el-icon-key',
                '4':'el-icon-shopping-cart-full',
                '5':'el-icon-data-line'
            },
            isCollapse:false,
        }
    },
    methods:{
        logout(){
            sessionStorage.clear()
            this.$message.success("退出成功!")
            this.$router.push('/login')
        },
        toggleButton(){
            this.isCollapse = !this.isCollapse
        }
    }
}
</script>

<style scoped>
.home-container{
    height: 100%;
}
.el-header{
    background-color: #373d41;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
}
.el-header .titel{
    display: flex;
    align-items: center;
}
.el-header .titel span{
    color:#fff;
    font-size:20px;
    padding-left: 20px;
}
.el-header .titel img{
    widows: 44px;
    height: 44px;
    border-radius: 50%;
}
.el-aside{
    background-color: #333744;
}
.el-main{
    background-color: #eaedf1;
}
.toggle-button{
    background-color: #4a5064;
    padding: 5px 0;
    color:#fff;
    text-align: center;
    cursor: pointer;
}
.el-submenu__title{
    width:200px!important;
}
</style>